package js;

import java.util.*;

public class q数位和排序 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int m = scan.nextInt();
        Map<Integer, Integer> map = new HashMap<>();

        for(int i = 1;i<=n;i++){
            int sum = 0;
            int temp = i;
            while (temp>0){
                sum += temp%10;
                temp /=10;
            }
            map.put(i,sum);
        }

        List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.entrySet());

        Collections.sort(list, Map.Entry.comparingByValue());

        // System.out.println(list );
        System.out.println(list.get(m-1).getKey());
    }
}
